<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    let detail_1_edit_statau = 3;
    WfForm.bindFieldChangeEvent("field204949", function(obj,id,value){
        WfForm.changeFieldValue("field214442", {value:""});
        WfForm.changeFieldValue("field208946", {value:""});
        WfForm.changeFieldValue("field218942", {value:""});
        WfForm.changeFieldValue("field231943", {value:""});
        });
    
    WfForm.bindFieldChangeEvent("field218942", function(obj,id,value){
        WfForm.changeFieldValue("field208946", {value:""});
        WfForm.changeFieldValue("field219442", {value:""});
        WfForm.changeFieldValue("field231943", {value:""});
    });
    
    WfForm.bindFieldChangeEvent("field213442", function(obj,id,value){
        if(value == 1 || value == 2)
            detail_1_edit_statau = 2;
        else
            detail_1_edit_statau = 3;
        changeEditArtribute(detail_1_edit_statau);
    });
    
    WfForm.registerAction(WfForm.ACTION_ADDROW+"1", function(index) {
        changeEditArtribute(detail_1_edit_statau);
    }); 
    /*明细表隐藏时，取消工号必填。防止用户点击添加明细，然后又切换隐藏明细，导致提交不了表单*/
    WfForm.bindFieldChangeEvent("field204949", doChangeEditArtribute );
    function doChangeEditArtribute(obj,id,value) {
        if($("#field213442").val() != 0 && $("#field204949").val() == 0) {
            return;
        }
        if(value=='') {
            return;
        }else if(value != 0) {
            //明细的工号变成非必填
            detail_1_edit_statau = 2;
            changeEditArtribute(detail_1_edit_statau);
        }else {
            //明细的工号变成必填
            detail_1_edit_statau = 3;
            changeEditArtribute(detail_1_edit_statau);
        }
    }
    function changeEditArtribute(editState){
        let detailrow = WfForm.getDetailRowCount("detail_1");
        let str = WfForm.getDetailAllRowIndexStr("detail_1");
        let arr = str.split(",");
        for (var i = 0; i < arr.length; i++) {
            WfForm.changeFieldAttr("field232942"+"_"+arr[i], editState);
            WfForm.changeFieldAttr("field204965"+"_"+arr[i], editState);
        }
    } 
    
    //標記明細2和明细3的显隐状态，明細表2和3实际是用显示联动隐藏的 --start
    let bianGengLeiXing_ID = "field211942";
    let markDetail_2_Show_ID = "field229942";
    let markDetail_3_Show_ID = "field229943";
    let show = "0";
    let hide  = "1";
    WfForm.bindFieldChangeEvent( bianGengLeiXing_ID,  function(obj,id,value) {
        changeDetailShow(0,0,WfForm.getFieldValue(bianGengLeiXing_ID));
    });
    function changeDetailShow(obj,id,value) {
        let value_str = value + "";
        if(value_str == "") {
            WfForm.changeFieldValue(markDetail_2_Show_ID , {value: hide});
            WfForm.changeFieldValue(markDetail_3_Show_ID , {value: hide});
        }
        if(value_str.indexOf("0") >= 0)
            WfForm.changeFieldValue(markDetail_2_Show_ID , {value: show});
        else
            WfForm.changeFieldValue(markDetail_2_Show_ID , {value: hide});

        if(value_str.indexOf("1") >= 0 || value_str.indexOf("2") >= 0)
            WfForm.changeFieldValue(markDetail_3_Show_ID , {value: show});
        else
            WfForm.changeFieldValue(markDetail_3_Show_ID , {value: hide});
    }
    
    WfForm.bindFieldChangeEvent("field204949", 
        function doChangeEditArtribute(obj,id,value)
            {
                  if(value != 3)
                  {
                        WfForm.changeFieldValue(markDetail_2_Show_ID , {value: hide});
                        WfForm.changeFieldValue(markDetail_3_Show_ID , {value: hide});
                   }
                   else
                         changeDetailShow(0,0,WfForm.getFieldValue(bianGengLeiXing_ID));
                   //checkDetail();
            }
    );
    
    //標記明細2和明细3的显隐状态，明細表2和3实际是用显示联动隐藏的 --start
    //提交表單之前，檢查明显表2和3的显示状态，如果隐藏就把字段属性改为编辑，防止用户手贱，切换明显表又不填明显表，导致提交不了 ---start
    
    checkCustomize = function()
    {
          if(checkDetail() == true)
               return true;
          else
          {
               return false;
           }
    }
    function checkDetail()
    {
        let onlyRead = 1;
            let tip_str = "";
            
           
    
            if(WfForm.getFieldValue(markDetail_2_Show_ID) == show && WfForm.getDetailRowCount("detail_2") <= 0)
            {
                   tip_str += "變更節點處理人明細，沒有填寫!  ";
             }
             if(WfForm.getFieldValue(markDetail_3_Show_ID) == show && WfForm.getDetailRowCount("detail_3") <= 0)
            {
                   tip_str += "轉移待辦/已辦事宜明細，沒有填寫!  ";
             }
             if(tip_str.length > 0)
             {
                    WfForm.showMessage(tip_str, 2, 4);
                   return false;
              }
    
        if(WfForm.getFieldValue(markDetail_2_Show_ID) != show)
        {
            let detail_artribute_id_arr_2 = ["field228442","field230944","field223443", "field230944","field210942","field227445","field225942"];
            changeDetailEditArtribute("detail_2", detail_artribute_id_arr_2, onlyRead);
        }
        if(WfForm.getFieldValue(markDetail_3_Show_ID) != show)
        {
            let detail_artribute_id_arr_3 = ["field213943","field227447","field210945","field225944"];
            changeDetailEditArtribute("detail_3", detail_artribute_id_arr_3, onlyRead);
        }
            return true;
    }
    //"detail_1"
    function changeDetailEditArtribute(detail_name, detail_artribute_id_arr, editState)
    {
        let detailrow = WfForm.getDetailRowCount(detail_name);
        let str = WfForm.getDetailAllRowIndexStr(detail_name);
        let arr = str.split(",");
        for (let i = 0; i < arr.length; i++) 
        {
            for(let j = 0; j < detail_artribute_id_arr.length; j++)
            {
                WfForm.changeFieldAttr(detail_artribute_id_arr[j]+"_"+arr[i], editState);
            }
        }
    }
    
    //提交表單之前，檢查明显表2和3的显示状态，如果隐藏就把字段属性改为编辑，防止用户手贱，切换明显表又不填明显表，导致提交不了 ---end
    </script>